﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using System;
using System.Runtime.InteropServices;
using Beyond;
using Beyond.Ant;
using AOT;


namespace Beyond {

    public class CLBridgeImpl : CLBridge {
#if UNITY_IPHONE
        const String DllName = "__Internal";
#elif UNITY_ANDROID
        const String DllName = "pkpdz";
#else
        const String DllName = "beyond";
#endif

        // -----------------------------------------------------------------------
        [DllImport(DllName, EntryPoint = "__Free")]
        private static extern void __Free(IntPtr p);
        public void Free(IntPtr p) {
            __Free(p);
        }

        [DllImport(DllName, EntryPoint = "__Platform")]
        private static extern int __Platform();
        public int Platform() {
            return __Platform();
        }

        [DllImport(DllName, EntryPoint = "beyondVersion")]
        private static extern IntPtr __beyondVersion();
        public IntPtr beyondVersion() {
            return __beyondVersion();
        }

        // -----------------------------------------------------------------------
        [DllImport(DllName, EntryPoint = "__Log_level")]
        private static extern int __Log_level();
        public int Log_level() {
            return __Log_level();
        }
        [DllImport(DllName, EntryPoint = "__Log_RegisterFunc")]
        private static extern void __Log_RegisterFunc(BELog.LogFunc func);
        public void Log_RegisterFunc(BELog.LogFunc func) {
            __Log_RegisterFunc(func);
        }

        // -----------------------------------------------------------------------
        [DllImport(DllName, EntryPoint = "__App_initialize")]
        private static extern void __App_initialize(int serviceId, int serviceVersion, int channelId, string props);
        public void App_initialize(int serviceId, int serviceVersion, int channelId, string props) {
            __App_initialize(serviceId, serviceVersion, channelId, props);
        }
        [DllImport(DllName, EntryPoint = "__App_onStageEnter")]
        private static extern void __App_onStageEnter();
        public void App_onStageEnter() {
            __App_onStageEnter();
        }
        [DllImport(DllName, EntryPoint = "__App_getAppVersion")]
        private static extern int __App_getAppVersion();
        public int App_getAppVersion() {
            return __App_getAppVersion();
        }
        [DllImport(DllName, EntryPoint = "__App_getAppPackageName")]
        private static extern IntPtr __App_getAppPackageName();
        public IntPtr App_getAppPackageName() {
            return __App_getAppPackageName();
        }
        [DllImport(DllName, EntryPoint = "__App_RegisterPauseAndResumeFunc")]
        private static extern void __App_RegisterPauseAndResumeFunc(Action pauseFunc, Action resumeFunc);
        public void App_RegisterPauseAndResumeFunc(Action pauseFunc, Action resumeFunc) {
            __App_RegisterPauseAndResumeFunc(pauseFunc, resumeFunc);
        }
        [DllImport(DllName, EntryPoint = "__App_destroy")]
        private static extern void __App_destroy();
        public void App_destroy() {
            __App_destroy();
        }
        [DllImport(DllName, EntryPoint = "__App_exit")]
        private static extern void __App_exit();
        public void App_exit() {
            __App_exit();
        }
        [DllImport(DllName, EntryPoint = "__App_setPermissionCallback")]
        private static extern void __App_setPermissionCallback(App.PermissionCallbackDelegate dele);
        public void App_setPermissionCallback(App.PermissionCallbackDelegate dele) {
            __App_setPermissionCallback(dele);
        }
        [DllImport(DllName, EntryPoint = "__App_checkPermission")]
        private static extern bool __App_checkPermission(string permission);
        public bool App_checkPermission(string permission) {
            return __App_checkPermission(permission);
        }
        [DllImport(DllName, EntryPoint = "__App_checkAndRequestPermission")]
        private static extern bool __App_checkAndRequestPermission(string permission, int flag);
        public bool App_checkAndRequestPermission(string permission, int flag) {
            return __App_checkAndRequestPermission(permission, flag);
        }
        [DllImport(DllName, EntryPoint = "__App_sendNotification")]
        private static extern void __App_sendNotification(int id, string content, int delay);
        public void App_sendNotification(int id, string content, int delay) {
            __App_sendNotification(id, content, delay);
        }
        [DllImport(DllName, EntryPoint = "__App_openWebBrowser")]
        private static extern void __App_openWebBrowser(string url, int mode);
        public void App_openWebBrowser(string url, int mode) {
            __App_openWebBrowser(url, mode);
        }
        [DllImport(DllName, EntryPoint = "__App_evaluateApp")]
        private static extern void __App_evaluateApp(bool intro);
        public void App_evaluateApp(bool intro) {
            __App_evaluateApp(intro);
        }
        [DllImport(DllName, EntryPoint = "__App_shareApp")]
        private static extern void __App_shareApp(string title, string content);
        public void App_shareApp(string title, string content) {
            __App_shareApp(title, content);
        }
        [DllImport(DllName, EntryPoint = "__App_setShareAppCallback")]
        private static extern void __App_setShareAppCallback(App.ShareAppCallbackDelegate dele);
        public void App_setShareAppCallback(App.ShareAppCallbackDelegate dele) {
            __App_setShareAppCallback(dele);
        }

        // -----------------------------------------------------------------------
        [DllImport(DllName, EntryPoint = "__AppInfo_synchronize")]
        private static extern void __AppInfo_synchronize(AppInfo.SyncDelegate dele);
        public void AppInfo_synchronize(AppInfo.SyncDelegate dele) {
            __AppInfo_synchronize(dele);
        }
        [DllImport(DllName, EntryPoint = "__AppInfo_getState")]
        private static extern int __AppInfo_getState();
        public int AppInfo_getState() {
            return __AppInfo_getState();
        }
        [DllImport(DllName, EntryPoint = "__AppInfo_setState")]
        private static extern void __AppInfo_setState(int state);
        public void AppInfo_setState(int state) {
            __AppInfo_setState(state);
        }

        // -----------------------------------------------------------------------
        [DllImport(DllName, EntryPoint = "__Files_getRoot")]
        private static extern IntPtr __Files_getRoot();
        public IntPtr Files_getRoot() {
            return __Files_getRoot();
        }

        // -----------------------------------------------------------------------
        [DllImport(DllName, EntryPoint = "__DeviceScreen_getDeviceScreenSize")]
        private static extern void __DeviceScreen_getDeviceScreenSize(float[] size);
        public void DeviceScreen_getDeviceScreenSize(float[] size) {
            __DeviceScreen_getDeviceScreenSize(size);
        }
        [DllImport(DllName, EntryPoint = "__DeviceScreen_getSafeAreaInNDC")]
        private static extern void __DeviceScreen_getSafeAreaInNDC(float[] rect);
        public void DeviceScreen_getSafeAreaInNDC(float[] rect) {
            __DeviceScreen_getSafeAreaInNDC(rect);
        }
        [DllImport(DllName, EntryPoint = "__Device_isAppleIPad")]
        private static extern bool __Device_isAppleIPad();
        public bool Device_isAppleIPad() {
            return __Device_isAppleIPad();
        }
        [DllImport(DllName, EntryPoint = "__Device_isAppleIPhoneX")]
        private static extern bool __Device_isAppleIPhoneX();
        public bool Device_isAppleIPhoneX() {
            return __Device_isAppleIPhoneX();
        }
        [DllImport(DllName, EntryPoint = "__Device_registerPermission")]
        private static extern void __Device_registerPermission(int pid);
        public void Device_registerPermission(int pid) {
            __Device_registerPermission(pid);
        }
        [DllImport(DllName, EntryPoint = "__Device_openAppSettings")]
        private static extern void __Device_openAppSettings();
        public void Device_openAppSettings() {
            __Device_openAppSettings();
        }
        [DllImport(DllName, EntryPoint = "__Device_requestPermission")]
        private static extern void __Device_requestPermission(int pid);
        public void Device_requestPermission(int pid) {
            __Device_requestPermission(pid);
        }
        [DllImport(DllName, EntryPoint = "__Device_checkPermission")]
        private static extern int __Device_checkPermission(int pid);
        public int Device_checkPermission(int pid) {
            return __Device_checkPermission(pid);
        }

        [DllImport(DllName, EntryPoint = "__Locale_getPlainMessage")]
        private static extern IntPtr __Locale_getPlainMessage(string key);
        public IntPtr Locale_getPlainMessage(string key) {
            return __Locale_getPlainMessage(key);
        }

        // -----------------------------------------------------------------------
        [DllImport(DllName, EntryPoint = "__Purchase_initialize")]
        private static extern void __Purchase_initialize(string props, Purchase.CallbackDelegate dele);
        public void Purchase_initialize(string props, Purchase.CallbackDelegate dele) {
            __Purchase_initialize(props, dele);
        }
        [DllImport(DllName, EntryPoint = "__Purchase_setFree")]
        private static extern void __Purchase_setFree(bool v);
        public void Purchase_setFree(bool v) {
            __Purchase_setFree(v);
        }
        [DllImport(DllName, EntryPoint = "__Purchase_getPayLevel")]
        private static extern int __Purchase_getPayLevel();
        public int Purchase_getPayLevel() {
            return __Purchase_getPayLevel();
        }
        [DllImport(DllName, EntryPoint = "__Purchase_pay")]
        private static extern void __Purchase_pay(long userId, int goodsId, string goodsName, int amount, int locationId, string parms);
        public void Purchase_pay(long userId, int goodsId, string goodsName, int amount, int locationId, string parms) {
            __Purchase_pay(userId, goodsId, goodsName, amount, locationId, parms);
        }
        [DllImport(DllName, EntryPoint = "__Purchase_restore")]
        private static extern void __Purchase_restore(long userId, int goodsId, string goodsName, int amount, int locationId, string parms);
        public void Purchase_restore(long userId, int goodsId, string goodsName, int amount, int locationId, string parms) {
            __Purchase_restore(userId, goodsId, goodsName, amount, locationId, parms);
        }
        [DllImport(DllName, EntryPoint = "__Purchase_setSubscriptionListener")]
        private static extern void __Purchase_setSubscriptionListener(Purchase.SubscriptionDelegate dele);
        public void Purchase_setSubscriptionListener(Purchase.SubscriptionDelegate dele) {
            __Purchase_setSubscriptionListener(dele);
        }
        [DllImport(DllName, EntryPoint = "__Purchase_addSubscriptionGoods")]
        private static extern void __Purchase_addSubscriptionGoods(int goodsId, string parms);
        public void Purchase_addSubscriptionGoods(int goodsId, string parms) {
            __Purchase_addSubscriptionGoods(goodsId, parms);
        }
        [DllImport(DllName, EntryPoint = "__Purchase_checkSubscription")]
        private static extern void __Purchase_checkSubscription(bool refreshFromServer);
        public void Purchase_checkSubscription(bool refreshFromServer) {
            __Purchase_checkSubscription(refreshFromServer);
        }

        // -----------------------------------------------------------------------
        [DllImport(DllName, EntryPoint = "__Ads_initialize")]
        private static extern void __Ads_initialize(Ads.CallbackDelegate dele);
        public void Ads_initialize(Ads.CallbackDelegate dele) {
            __Ads_initialize(dele);
        }
        [DllImport(DllName, EntryPoint = "__Ads_isReady")]
        private static extern bool __Ads_isReady(int type);
        public bool Ads_isReady(int type) {
            return __Ads_isReady(type);
        }
        [DllImport(DllName, EntryPoint = "__Ads_showAd")]
        private static extern void __Ads_showAd(int type, int style, string parm);
        public void Ads_showAd(int type, int style, string parm) {
            __Ads_showAd(type, style, parm);
        }
        [DllImport(DllName, EntryPoint = "__Ads_hideAd")]
        private static extern void __Ads_hideAd(int type);
        public void Ads_hideAd(int type) {
            __Ads_hideAd(type);
        }

        // -----------------------------------------------------------------------
        [DllImport(DllName, EntryPoint = "__Sns_fbInitialize")]
        private static extern void __Sns_fbInitialize(Sns.FBCallbackDelegate dele);
        public void Sns_fbInitialize(Sns.FBCallbackDelegate dele) {
            __Sns_fbInitialize(dele);
        }
        [DllImport(DllName, EntryPoint = "__Sns_fbIsEnabled")]
        private static extern bool __Sns_fbIsEnabled();
        public bool Sns_fbIsEnabled() {
            return __Sns_fbIsEnabled();
        }
        [DllImport(DllName, EntryPoint = "__Sns_fbShare")]
        private static extern void __Sns_fbShare(string title, string desc);
        public void Sns_fbShare(string title, string desc) {
            __Sns_fbShare(title, desc);
        }

        // -----------------------------------------------------------------------
        [DllImport(DllName, EntryPoint = "__Statistics_logRegistration")]
        private static extern void __Statistics_logRegistration(string method);
        public void Statistics_logRegistration(string method) {
            __Statistics_logRegistration(method);
        }
        [DllImport(DllName, EntryPoint = "__Statistics_logUserLevel")]
        private static extern void __Statistics_logUserLevel(int level);
        public void Statistics_logUserLevel(int level) {
            __Statistics_logUserLevel(level);
        }
        [DllImport(DllName, EntryPoint = "__Statistics_logLevel")]
        private static extern void __Statistics_logLevel(int level, int state, string parms);
        public void Statistics_logLevel(int level, int state, string parms) {
            __Statistics_logLevel(level, state, parms);
        }
        [DllImport(DllName, EntryPoint = "__Statistics_logProperty")]
        private static extern void __Statistics_logProperty(int action, int propId, string propName, int price, int number, string parms);
        public void Statistics_logProperty(int action, int propId, string propName, int price, int number, string parms) {
            __Statistics_logProperty(action, propId, propName, price, number, parms);
        }
        [DllImport(DllName, EntryPoint = "__Statistics_logEvent")]
        private static extern void __Statistics_logEvent(string eventId, string parms);
        public void Statistics_logEvent(string eventId, string parms) {
            __Statistics_logEvent(eventId, parms);
        }

        // -----------------------------------------------------------------------
        [DllImport(DllName, EntryPoint = "__Ant_setServerAddress")]
        private static extern void __Ant_setServerAddress(string address);
        public void Ant_setServerAddress(string address) {
            __Ant_setServerAddress(address);
        }
        [DllImport(DllName, EntryPoint = "__Ant_getUserId")]
        private static extern long __Ant_getUserId();
        public long Ant_getUserId() {
            return __Ant_getUserId();
        }
        [DllImport(DllName, EntryPoint = "__Ant_openCustomerSeviceWindow")]
        private static extern void __Ant_openCustomerSeviceWindow();
        public void Ant_openCustomerSeviceWindow() {
            __Ant_openCustomerSeviceWindow();
        }

        [DllImport(DllName, EntryPoint = "__Ant_PushNotification_sendAll")]
        private static extern void __Ant_PushNotification_sendAll();
        public void Ant_PushNotification_sendAll() {
            __Ant_PushNotification_sendAll();
        }
        [DllImport(DllName, EntryPoint = "__Ant_PushNotification_clearAll")]
        private static extern void __Ant_PushNotification_clearAll();
        public void Ant_PushNotification_clearAll() {
            __Ant_PushNotification_clearAll();
        }

        [DllImport(DllName, EntryPoint = "__Ant_ServiceSetting_getSetting")]
        private static extern IntPtr __AntServiceSetting_getSetting(string key, string defaultValue, int cacheTimes);
        public IntPtr AntServiceSetting_getSetting(string key, string defaultValue, int cacheTimes) {
            return __AntServiceSetting_getSetting(key, defaultValue, cacheTimes);
        }

        // -----------------------------------------------------------------------
        [DllImport(DllName, EntryPoint = "__Ant_InPromotion_synchronize")]
        private static extern void __Ant_InPromotion_synchronize(InPromotion.SyncDelegate dele);
        public void Ant_InPromotion_synchronize(InPromotion.SyncDelegate dele) {
            __Ant_InPromotion_synchronize(dele);
        }
        [DllImport(DllName, EntryPoint = "__Ant_InPromotion_setStyle")]
        private static extern void __Ant_InPromotion_setStyle(int style);
        public void Ant_InPromotion_setStyle(int style) {
            __Ant_InPromotion_setStyle(style);
        }
        [DllImport(DllName, EntryPoint = "__Ant_InPromotion_click")]
        private static extern void __Ant_InPromotion_click(string icon);
        public void Ant_InPromotion_click(string icon) {
            __Ant_InPromotion_click(icon);
        }

    }

}